#ifndef _ROBOT_H_
#define _ROBOT_H_

#include <pthread.h>
#include <stdint.h>
#include <map>
#include <sstream>

using namespace std;

class Robot
{
public:
	static int32_t init();
	static int32_t destroy();
	static int32_t create(uint32_t);
	static int32_t remove(uint32_t);
	static Robot *get(uint32_t id);	

	Robot(uint32_t id);
	uint32_t getid() const { return m_id; }
	void loop();

	// 连接函数
	int32_t connect(const string &sAddr);
	int32_t send(const string &s);
	int32_t recv(const string &s);
	void error(const string &s);

private:
	static map<uint32_t, Robot* > m_mrobots;
	static pthread_mutex_t m_mutex;

	uint32_t m_id;
};

#define log(level,id,x) do \
	{\
		ostringstream ss; \
		ss << x; \
		goLog(level, id, ss.str().c_str()); \
	} while (0);


#endif
